package com.wyd.flowable;

import com.wyd.flowable.listener.TestListener;
import lombok.RequiredArgsConstructor;
import org.flowable.common.engine.api.delegate.event.FlowableEventDispatcher;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;

/**
 * Flowable添加全局监听器
 *
 * @author zhaowei
 */
@Configuration
@RequiredArgsConstructor
public class FlowableGlobalListenerConfig implements ApplicationListener<ContextRefreshedEvent> {

    private final SpringProcessEngineConfiguration configuration;

    private final FlowableEventListener2 listener;
    private final FlowableEventListener3 listener3;
    private final TestListener testListener;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        FlowableEventDispatcher dispatcher = configuration.getEventDispatcher();
        // 任务创建全局监听 加入顺序就是执行顺序
//        dispatcher.addEventListener(listener, FlowableEngineEventType.TASK_CREATED);
//        dispatcher.addEventListener(listener3, FlowableEngineEventType.TASK_CREATED);
        dispatcher.addEventListener(testListener);
    }
}

